//
//  YPath.m
//  YuiKe
//
//  Created by yuike6 yuike6 on 11-10-14.
//  Copyright 2011年 yuike. All rights reserved.
//

#import "YPath.h"
#import "YFile.h"

@implementation YPath


- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    
    return self;
}

+ (BOOL)createDirectory:(NSString *)path withAttributes:(NSDictionary*)attributes
{
	NSError* error = nil;
	return [[NSFileManager defaultManager] createDirectoryAtPath:path withIntermediateDirectories:YES attributes:attributes error:&error];
}

//referenced: http://stackoverflow.com/questions/2188469/calculate-the-size-of-a-folder
+ (unsigned long long int)sizeOfFolderPath:(NSString *)path
{
    unsigned long long int totalSize = 0;
    
	NSEnumerator* enumerator = [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath:path error:nil] objectEnumerator];	
    NSString* fileName;
    while((fileName = [enumerator nextObject]))
	{
		totalSize += [[[NSFileManager defaultManager] attributesOfItemAtPath:[path stringByAppendingPathComponent:fileName] error:nil] fileSize];
    }
	
    return totalSize;	
}

+ (void) removeDirectoryIncludeSubDirectory: (NSString *) dir_path 
                              includeSubDir:(BOOL) b_include
{
    NSEnumerator* enumerator = [[[NSFileManager defaultManager] subpathsOfDirectoryAtPath:dir_path error:nil] objectEnumerator];	
    NSString* fileName;
    while((fileName = [enumerator nextObject]))
	{
//		NSString * fileFullPath = [dir_path stringByAppendingPathComponent:fileName];
 
    }
    
}

+ (void) removeDirectory:(NSString *) path
{
    [[NSFileManager defaultManager] removeItemAtPath:path error:nil];
}

+ (NSString *) Combine:(NSString *) path1 combinePath:(NSString *) path2
{
    NSString * path = [path1 stringByAppendingPathComponent:path2];
    return path;
}

+ (NSString *) fileName:(NSString *) path
{
    return [path lastPathComponent];
}


+ (NSString *) extensionName:(NSString *) path
{
    return [path pathExtension];
}


@end
